package com.itboye.zhujia.controller;

import com.itboye.zhujia.base.MyApplcation;
import com.itboye.zhujia.constants.SPContants;
import com.itboye.zhujia.util.DebugLog;
import com.itboye.zhujia.util.SPUtils;

import android.app.Activity;

/**
 * 登录相关控制类--状态模式</br></br>
 * 
 * 登录成功后调用setLoginState(new LoginedState());</br></br>
 * 退出登录后调用setLoginState(new UnLoginState());</br></br>
 * 进入主Activity前一定要设置一次，要么登录要么未登录</br></br>
 * @author Young
 *
 */
public class LoginController {

	private static ILoginState loginState=new UnLoginState();

	public static void setLoginState(ILoginState loginState) {
		
		LoginController.loginState = loginState;
		if (loginState instanceof UnLoginState) {
			DebugLog.v("bytag", "未登录。。。");
//			PushAgent mPushAgent = PushAgent.getInstance(App.ctx);
//			mPushAgent.disable(new IUmengUnregisterCallback() {
//				
//				@Override
//				public void onUnregistered(String arg0) {
//					// TODO Auto-generated method stub
//					DebugLog.v("bytag", "停止推送:"+arg0);
//				}
//			});
		}else if (loginState instanceof LoginedState) {
			DebugLog.v("bytag", "已登录。。。");
//			PushAgent mPushAgent = PushAgent.getInstance(App.ctx);
			//mPushAgent.setPushIntentServiceClass(MyPushIntentService.class);
//			mPushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SDK_ENABLE);
//			mPushAgent.onAppStart();
			//开启推送并设置注册的回调处理
//			if (!mPushAgent.isEnabled()) {
//				mPushAgent.enable(new IUmengRegisterCallback() {

//					@Override
//					public void onRegistered(String registrationId) {
						//onRegistered方法的参数registrationId即是device_token
						
//						setExclusiveAlias(registrationId);
//					}
//				});
//			}
			
//			String device_token = UmengRegistrar.getRegistrationId(App.ctx);
//			if (!TextUtils.isEmpty(device_token)) {
//				setExclusiveAlias(device_token);
//			}
		}
	}

	private static void setExclusiveAlias(String registrationId){
		String uid=(String)SPUtils.get(MyApplcation.ctx, null, SPContants.USER_ID, "");
//		PushAgent mPushAgent = PushAgent.getInstance(MyApplcation.ctx);
//		mPushAgent.setExclusiveAlias(uid, "sunsun");
		DebugLog.v("bytag", "setExclusiveAlias   token:",registrationId," alian:",uid, "  type:","sunsun");
		 
//		//登录后绑定设备
//		MyJsonRequest<String> request = new MyJsonRequest.Builder<String>().apiVer("100")
//				.typeKey("BY_Device_bind")
//				.param("uid", (String) SPUtils.get(App.ctx, null, SPContants.USER_ID, ""))
//				.param("device_token",registrationId)
//				.param("version",android.os.Build.VERSION.RELEASE)
//				.param("device_type","Android")
//				.requestListener(new XRequestListener<String>() {
//
//					@Override
//					public void onResponse(String response) {
//						 
//					}
//				}).errorListener(new XErrorListener() {
//
//					@Override
//					public void onErrorResponse(Exception exception, int code, String msg) {
//						if (exception instanceof CodeErrorException) {
//							Toast.makeText(App.ctx, msg, 0).show();
//						} else {
//							Toast.makeText(App.ctx, exception.toString(), 0).show();
//						}
//
//					}
//				}).build();
//		HttpRequest.getDefaultRequestQueue().add(request);
//	 
 
	}
	
	public static void onMyMoneyClick(Activity act,
			Object data) {
		loginState.onMyMoneyClick(act, data);
	}
	public static void onMyAppointmentClick(Activity act,
			Object data) {
		loginState.onMyAppointmentClick(act, data);
	}
	public static void onMyCollectionClick(Activity act,
			Object data) {
		loginState.onMyCollectionClick(act, data);
	}
	public static void onMySignClick(Activity act,
			Object data) {
		loginState.onMySignClick(act, data);
	}
	public static void onMyPersonalCenter(Activity act,
			Object data) {
		loginState.onMyPersonalCenter(act, data);
	}
}
